package com.zm.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("abc")
public class DemoAction {
    @RequestMapping("toIdx")
    public String toIndex(){
        // 1.请求转发 2.响应重定向
//        return "forward:index.html";
        return "redirect:../index.html";
    }

    @RequestMapping("now")
    @ResponseBody    //Controller + RequestBody
    public Date now(){
        return new Date();
    }

    @RequestMapping("**/myname")
    @ResponseBody    //Controller + RequestBody
    public String mname(){
        return "zhangsan";
    }

    @RequestMapping(path = "doget",method = RequestMethod.GET)
    @ResponseBody    //Controller + RequestBody
    public String doGet(){
        return "doGet";
    }

    @RequestMapping(path = "dogetorpost",method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody    //Controller + RequestBody
    public String doGetAndPost(){
        return "doGetorPost";
    }


}
